using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace foldertotal
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter folder");
            string path = Console.ReadLine();
            string output = "";
            DirectoryInfo dir = new DirectoryInfo(path);

            long foldersize = DirSize(dir);

            if (foldersize >= 1024)
            { 
                foldersize = foldersize / 1024;
                output = "KB";
            }
            if (foldersize >= 1024) 
            {
                foldersize = foldersize / 1024;
                output = "MB";
            }
            if (foldersize >= 1024)
            {
                foldersize = foldersize / 1024;
                output = "GB";
            }

            Console.WriteLine(Convert.ToString(foldersize) + output);
            Console.ReadLine();
            

        }

        private static long DirSize(DirectoryInfo d)
        {
            long size = 0;
            
            

            FileInfo[] fis = d.GetFiles();

            foreach (FileInfo fi in fis)
            {
                size += fi.Length;
            }

            DirectoryInfo[] dis = d.GetDirectories();
            foreach (DirectoryInfo di in dis)
            {
                size += DirSize(di);
            }
            return size;
        }
    }
}
